package org.example.m7_17;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int T = in.nextInt();
        for(int i = 0;i < T;i++){
            int n = in.nextInt();
            int k = in.nextInt();
            String str = in.next();
            int score = 0;
            int count = 0;
            for(int j = 0;j < n;j++){
                if(str.charAt(i) == 'W'){
                    if(count > 1){
                        score += k;
                    }else{
                        score++;
                    }
                    count++;
                }else{
                    count = 0;
                    score--;
                }
            }
            System.out.println(score);

        }
    }
}
